package io;

import java.io.*;

/**
@Auther: MFM
@Date: 2021/8/5 - 08 - 05 - 14:47 
@version: 1.0
*/

public class outputStreamDemo {

    public static void outputStream(File file) throws Exception{
        OutputStream output = new FileOutputStream(file,true);
        String str = "2020年，至现在，中国已获得34枚金牌\n";
        byte[] bts = str.getBytes();
        output.write(bts);
        output.flush();
        output.close();
    }

    public static void InputStreamReaderDemo(InputStream stream) throws Exception{
        InputStreamReader input = new InputStreamReader(stream);
        char[] chars = new char[1024];
        int size = 0;
        while ((size = input.read(chars))>-1){
            System.out.println(new String(chars,0,size));
        }
        input.close();
    }

    public static void BufferReader(Reader reader) throws Exception{
        BufferedReader bufferedReader = new BufferedReader(reader);
        bufferedReader.mark(10);
        char[] chars = new char[10];
        bufferedReader.read(chars);
        System.out.println(chars);

        bufferedReader.read(chars);
        System.out.println(chars);
    }

    public static void copyFile(File file) throws  Exception{
        InputStream input = new FileInputStream(file);
        OutputStream output = new FileOutputStream("./file/aa/a.txt");
        byte[] bts = new byte[1024];
        int size = -1;
        while ((size=input.read(bts))>-1){
            output.write(bts,0,size);
        }
        output.flush();
        input.close();
        output.close();
    }

    public static void main(String[] args) throws Exception{
        File file = new File("./file/aa/b.txt");
        copyFile(file);
    }
}
